#!/bin/sh
#
# Create the public and private keys that are used for 'scppk' and 'sshpk'.
#
# enchroot is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# enchroot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with enchroot. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (c) 2010 charles@kollar.com
#

SSHDIR=$HOME/.ssh
AUTHFILE=$SSHDIR/authorized_keys

#
# Check some assumptions...

if [ ! -d "$SSHDIR" ] ; then
  echo "Could not find directory $SSHDIR?"
  exit
fi

SSHDIR_FILEPERM="drwx------"
if [ "`ls -ld $SSHDIR | grep ^${SSHDIR_FILEPERM}`" == ""  ] ; then
  echo "File permissions on $SSHDIR are set wrong?"
  echo "They should be '$SSHDIR_FILEPERM'. "
  exit
fi

#
# Generate the public/private key pair to be used for 'public key authentication'...
/usr/bin/ssh-keygen -b 4096 -t rsa -f $AUTHFILE

echo
echo "Please copy the file '${AUTHFILE}.pub' to the server."
echo "This will likely be to the file '/home/PublicKeys/$USER/authorized_keys'"